package com.hospital.proxy;

import java.util.List;

import com.hospital.dao.IMsgDao;
import com.hospital.dao.impl.MsgDaoImpl;
import com.hospital.dbc.DatabaseConnection;
import com.hospital.vo.MsgBox;

public class MsgDaoProxy implements IMsgDao {
	IMsgDao dao = null;
	DatabaseConnection dbc = null;
	public MsgDaoProxy() {
		try {
			this.dbc = new DatabaseConnection();
		} catch (Exception e) {
			e.printStackTrace();
		}
		this.dao = new MsgDaoImpl(this.dbc.getConnection());
	}
	@Override
	public List<MsgBox> findAll(String keyWord, int startIndex, int count, boolean all)
			throws Exception {
		List<MsgBox> list = null;
		try {
			list = this.dao.findAll(keyWord, startIndex, count, all);
		} catch (Exception e) {
			throw e;
		} finally {
			this.dbc.close();
		}
		return list;
	}

	@Override
	public int count(String keyWord, boolean all) throws Exception {
		int count;
		try {
			count = this.dao.count(keyWord, all);
		} catch (Exception e) {
			throw e;
		} finally {
			this.dbc.close();
		}
		return count;
	}
	@Override
	public boolean doDel(int mid) throws Exception {
		boolean flag = false;
		try {
			flag = this.dao.doDel(mid);
		} catch (Exception e) {
			throw e;
		} finally {
			this.dbc.close();
		}
		return flag;
	}
	@Override
	public boolean doUpdate(int mid, boolean active) throws Exception {
		boolean flag = false;
		try {
			flag = this.dao.doUpdate(mid, active);
		} catch (Exception e) {
			throw e;
		} finally {
			this.dbc.close();
		}
		return flag;
	}
	@Override
	public boolean doCreate(MsgBox msg) throws Exception {
		boolean flag = false;
		try {
			flag = this.dao.doCreate(msg);
		} catch (Exception e) {
			throw e;
		} finally {
			this.dbc.close();
		}
		return flag;
	}
	@Override
	public boolean doReply(String reply, int mid) throws Exception {
		boolean flag = false;
		try {
			flag = this.dao.doReply(reply, mid);
		} catch (Exception e) {
			throw e;
		} finally {
			this.dbc.close();
		}
		return flag;
	}

}
